/**
 * 获取 url 中的参数
 * @param key
 * @param url
 */
export const getQuery = (key: string, url?: string) => {
  url = url || String(window.location.href)
  if (url.indexOf('#') !== -1) url = url.substring(0, url.indexOf('#'))
  const rts = []
  let rt: RegExpExecArray
  const queryReg = new RegExp('(^|\\?|&)' + key + '=([^&]*)(?=&|#|$)', 'g')
  while ((rt = queryReg.exec(url)) !== null) {
    rts.push(decodeURIComponent(rt[2]))
  }
  if (rts.length === 0) return null
  if (rts.length === 1) return rts[0]
  return rts
}
